package com.hmy.pig.service.impl;

import com.hmy.pig.domain.HmyPig;
import com.hmy.pig.domain.HmyPigOut;
import com.hmy.pig.mapper.PigMapper;
import com.hmy.pig.mapper.PigOutMapper;
import com.hmy.pig.service.PigOutService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author zhl
 * @descript 描述  猪只 出场业务层
 * @date 2024/2/2 15:55
 */
@Service
public class PigOutServiceImpl implements PigOutService {
    @Resource
    private PigOutMapper pigOutMapper;

    @Resource
    private PigMapper pigMapper;
    @Override
    public List<HmyPigOut> selectPigOutList(String pigCode, String pigOutType, String pigType, String pigOutTimeStart, String pigOutTimeEnd) {
        return pigOutMapper.selectPigOutList( pigCode, pigOutType,  pigType,  pigOutTimeStart,  pigOutTimeEnd);
    }

    @Override
    public int insertPigOut(HmyPigOut hmyPigOut) {

        int rows = pigOutMapper.insertPigOut(hmyPigOut);
        if (rows > 0){
            HmyPig hmyPig = new HmyPig();
            hmyPig.setPigCode(hmyPigOut.getPigCode());
            if ("1".equals(hmyPigOut.getPigOutType())) {
                hmyPig.setPigStatus("3");
            } else {
                hmyPig.setPigStatus("1");
            }
            pigMapper.updatePig(hmyPig);
        }
        return rows;
    }

    @Override
    public HmyPigOut selectPigOutByPigId(Long pigId) {
        return pigOutMapper.selectPigOutByPigId(pigId);
    }

    @Override
    public int updatePigOut(HmyPigOut hmyPigOut) {
        return pigOutMapper.updatePigOut(hmyPigOut);
    }

    @Override
    public int deletePigOutByPigId(Long pigId) {
        return pigOutMapper.deletePigOutByPigId(pigId);
    }

    @Override
    public int deletePigOutByPigIds(Long[] pigIds) {
        return pigOutMapper.deletePigOutByPigIds(pigIds);
    }
}
